import { runTest, testPath } from "../../../support";

const fixtures: [string, string, string, number, string?][] = [
  // [result, startDate, unit, amount, ?timezone]
  // typical amounts
  ["2020-02-28T10:30:50.900Z", "2020-02-28T10:30:50.905Z", "millisecond", 5],
  ["2020-02-28T10:30:50.900Z", "2020-02-28T10:30:55.9Z", "second", 5],
  ["2020-02-28T10:30:50.900Z", "2020-02-28T10:35:50.9Z", "minute", 5],
  ["2020-02-28T10:30:50.900Z", "2020-02-28T15:30:50.9Z", "hour", 5],
  ["2020-02-28T10:30:50.900Z", "2020-03-04T10:30:50.9Z", "day", 5],
  ["2020-02-28T10:30:50.900Z", "2020-07-28T10:30:50.9Z", "month", 5],
  ["2020-02-28T10:30:50.900Z", "2021-05-28T10:30:50.9Z", "quarter", 5],
  ["2020-02-28T10:30:50.900Z", "2025-02-28T10:30:50.9Z", "year", 5],
  // large amounts
  ["2020-02-28T10:30:50.900Z", "2020-02-28T10:30:51.1Z", "millisecond", 200],
  ["2020-02-28T10:30:50.900Z", "2020-02-28T10:34:10.9Z", "second", 200],
  ["2020-02-28T10:30:50.900Z", "2020-02-28T13:50:50.9Z", "minute", 200],
  ["2020-02-28T10:30:50.900Z", "2020-03-07T18:30:50.9Z", "hour", 200],
  ["2020-02-28T10:30:50.900Z", "2020-09-15T10:30:50.9Z", "day", 200],
  ["2020-02-28T10:30:50.900Z", "2036-10-28T10:30:50.9Z", "month", 200],
  ["2020-02-28T10:30:50.900Z", "2070-02-28T10:30:50.9Z", "quarter", 200],
  ["2020-02-28T10:30:50.900Z", "2220-02-28T10:30:50.9Z", "year", 200],
  // small amounts
  ["2020-02-28T10:30:50.900Z", "2020-02-28T10:30:50.7Z", "millisecond", -200],
  ["2020-02-28T10:30:50.900Z", "2020-02-28T10:27:30.9Z", "second", -200],
  ["2020-02-28T10:30:50.900Z", "2020-02-28T07:10:50.9Z", "minute", -200],
  ["2020-02-28T10:30:50.900Z", "2020-02-20T02:30:50.9Z", "hour", -200],
  ["2020-02-28T10:30:50.900Z", "2019-08-12T10:30:50.9Z", "day", -200],
  ["2020-02-28T10:30:50.900Z", "2003-06-28T10:30:50.9Z", "month", -200],
  ["2020-02-28T10:30:50.900Z", "1970-02-28T10:30:50.9Z", "quarter", -200],
  ["2020-02-28T10:30:50.900Z", "1820-02-28T10:30:50.9Z", "year", -200],
  // extra
  ["2020-02-28T10:30:50Z", "2020-02-29T10:30:50Z", "day", 1], //leap year
  ["2021-02-28T10:30:50Z", "2021-03-01T10:30:50Z", "day", 1] //normal
  // timezone
  // All operations performed in UTC.
];

runTest(testPath(__filename), {
  $dateSubtract: fixtures.map(([result, date, unit, amount, timezone]) => [
    {
      startDate: new Date(date),
      unit,
      amount,
      timezone
    },
    new Date(result)
  ])
});
